using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Collections;
using System.Xml;

using System.Web;
using System.IO;


using WoWAddonRefresh.Entities;

namespace WoWAddonRefresh {
    public class RSS {
        public static List<Addon> GetCurseAddons(string url) {
            List<Addon> addons = new List<Addon>();
            try {
                XmlDocument xml = new XmlDocument();
                xml.Load(url);
                foreach (XmlNode node in xml.SelectNodes("/rss/channel/item")) {
                    Addon addon = new Addon();
                    addon.Name = node.SelectSingleNode("title").InnerText.Trim().Substring(5).Trim();
                    addon.NameLink = node.SelectSingleNode("link").InnerText.Trim();
                    addon.UploadDate = DateTime.Parse(node.SelectSingleNode("pubDate").InnerText);
                    addons.Add(addon);
                }

            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
            return addons;
        }


        public static List<Addon> GetWoWInterfaceAddons(string url) {
            List<Addon> addons = new List<Addon>();
            try {
                XmlDocument xml = new XmlDocument();
                xml.Load(url);
                foreach (XmlNode node in xml.SelectNodes("/rss/channel/item")) {
                    Addon addon = new Addon();
                    addon.Name = node.SelectSingleNode("title").InnerText.Trim().Substring(5).Trim();
                    addon.NameLink = node.SelectSingleNode("link").InnerText.Trim();
                    addon.UploadDate = DateTime.Parse(node.SelectSingleNode("pubDate").InnerText);
                    addons.Add(addon);
                }

            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
            return addons;
        }
    }


    
}
